1
|
|
|
function stripTrailingSlash(str: string): string { |
2
|
|
|
return str.endsWith("/") ? str.slice(0, -1) : str; |
3
|
|
|
} |
4
|
|
|
|
5
|
|
|
function isValidUrl(str: string): boolean { |
6
|
|
|
if (str.startsWith("http://") || str.startsWith("https://")) { |
7
|
|
|
try { |
8
|
|
|
const url = new URL(str); |
9
|
|
|
} catch (_) { |
10
|
|
|
return false; |
11
|
|
|
} |
12
|
|
|
return true; |
13
|
|
|
} |
14
|
|
|
return false; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
export function baseUrl(): string { |
18
|
|
|
const base = document.querySelector("meta[name='base-url']"); |
19
|
|
|
if (base !== null) { |
20
|
|
|
return stripTrailingSlash(base.getAttribute("content") ?? ""); |
21
|
|
|
} |
22
|
|
|
return ""; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
export function basePathname(): string { |
26
|
|
|
const base = baseUrl(); |
27
|
|
|
return isValidUrl(base) ? new URL(baseUrl()).pathname : ""; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
export function baseApiUrl(version = 1): string { |
31
|
|
|
return `${baseUrl()}/api/v${version}`; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
* @param imgFile The name of the img file, not inluding the /images/ path. |
37
|
|
|
*/ |
38
|
|
|
export function imageUrl(imgFile: string): string { |
39
|
|
|
return `${baseUrl()}/images/${imgFile}`; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Removes the base url or base pathname if the given url starts with them. |
44
|
|
|
* @param url |
45
|
|
|
*/ |
46
|
|
|
export function removeBaseUrl(url: string): string { |
47
|
|
|
const base = baseUrl(); |
48
|
|
|
if (url.startsWith(base)) { |
49
|
|
|
return url.substr(base.length); |
50
|
|
|
} |
51
|
|
|
const basePath = basePathname(); |
52
|
|
|
if (url.startsWith(basePath)) { |
53
|
|
|
return url.substr(basePath.length); |
54
|
|
|
} |
55
|
|
|
return url; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function applicationShow( |
59
|
|
|
locale: string, |
60
|
|
|
prefix: string, |
61
|
|
|
applicationId: number, |
62
|
|
|
jobId: number, |
63
|
|
|
): string { |
64
|
|
|
return `${baseUrl()}/${locale}/${prefix}/jobs/${jobId}/applications/${applicationId}`; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
function applicantShow( |
68
|
|
|
locale: string, |
69
|
|
|
prefix: string, |
70
|
|
|
applicantId: number, |
71
|
|
|
jobId: number, |
72
|
|
|
): string { |
73
|
|
|
return `${baseUrl()}/${locale}/${prefix}/jobs/${jobId}/applicants/${applicantId}`; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
export function managerApplicationShow( |
77
|
|
|
locale: string, |
78
|
|
|
applicationId: number, |
79
|
|
|
jobId: number, |
80
|
|
|
): string { |
81
|
|
|
return applicationShow(locale, "manager", applicationId, jobId); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
export function managerApplicantShow( |
85
|
|
|
locale: string, |
86
|
|
|
applicantId: number, |
87
|
|
|
jobId: number, |
88
|
|
|
): string { |
89
|
|
|
return applicantShow(locale, "manager", applicantId, jobId); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
export function managerEditProfile(locale: string): string { |
93
|
|
|
return `${baseUrl()}/${locale}/manager/profile`; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
export function managerJobIndex(locale: string): string { |
97
|
|
|
return `${baseUrl()}/${locale}/manager/jobs`; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
export function managerJobSummary(locale: string, jobId: number): string { |
101
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}`; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
export function managerJobPreview(locale: string, jobId: number): string { |
105
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/preview`; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
export function managerJobApplications(locale: string, jobId: number): string { |
109
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/applications`; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
export function managerScreeningPlan(locale: string, jobId: number): string { |
113
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/assessment-plan`; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
export function applicationReviewUpdate( |
117
|
|
|
locale: string, |
118
|
|
|
applicationId: number, |
119
|
|
|
): string { |
120
|
|
|
return `${baseApiUrl()}/applications/${applicationId}/review`; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
export function jobBuilderIntro(locale: string, jobId?: number): string { |
124
|
|
|
if (jobId) { |
125
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/intro`; |
126
|
|
|
} |
127
|
|
|
return `${baseUrl()}/${locale}/manager/job-builder/intro`; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
export function jobBuilderDetails(locale: string, jobId: number): string { |
131
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/details`; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
export function jobBuilderEnv(locale: string, jobId: number): string { |
135
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/environment`; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
export function jobBuilderImpact(locale: string, jobId: number): string { |
139
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/impact`; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
export function jobBuilderTasks(locale: string, jobId: number): string { |
143
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/tasks`; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
export function jobBuilderSkills(locale: string, jobId: number): string { |
147
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/skills`; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
export function jobBuilderReview(locale: string, jobId: number): string { |
151
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/review`; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
type FaqSection = "manager-who"; |
155
|
|
|
|
156
|
|
|
export function managerFaq(locale: string, faqSection?: FaqSection): string { |
157
|
|
|
const base = `${baseUrl()}/${locale}/manager/faq`; |
158
|
|
|
if (faqSection) { |
159
|
|
|
return `${base}#${faqSection}`; |
160
|
|
|
} |
161
|
|
|
return base; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
export function hrJobIndex(locale: string): string { |
165
|
|
|
return `${baseUrl()}/${locale}/hr/jobs`; |
166
|
|
|
} |
167
|
|
|
export function hrJobSummary(locale: string, jobId: number): string { |
168
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}`; |
169
|
|
|
} |
170
|
|
|
export function hrJobReview(locale: string, jobId: number): string { |
171
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/review`; |
172
|
|
|
} |
173
|
|
|
export function hrJobPreview(locale: string, jobId: number): string { |
174
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/preview`; |
175
|
|
|
} |
176
|
|
|
export function hrScreeningPlan(locale: string, jobId: number): string { |
177
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/assessment-plan`; |
178
|
|
|
} |
179
|
|
|
export function hrJobApplications(locale: string, jobId: number): string { |
180
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/applications`; |
181
|
|
|
} |
182
|
|
|
export const hrApplicationShow = ( |
183
|
|
|
locale: string, |
184
|
|
|
applicationId: number, |
185
|
|
|
jobId: number, |
186
|
|
|
): string => applicationShow(locale, "hr", applicationId, jobId); |
187
|
|
|
export const hrApplicantShow = ( |
188
|
|
|
locale: string, |
189
|
|
|
applicantId: number, |
190
|
|
|
jobId: number, |
191
|
|
|
): string => applicantShow(locale, "hr", applicantId, jobId); |
192
|
|
|
|
193
|
|
|
export function accountSettings(locale: string): string { |
194
|
|
|
return `${baseUrl()}/${locale}/settings`; |
195
|
|
|
} |
196
|
|
|
|